<?php
class Bagi_non_syahriyah extends CI_Model 
{

	function __construct()
	{
		parent::__construct();
	}

	function list_tagihan($id_m_j_pendidikan)
	{
		$this->db->select('*,(select count(id_m_tholabah) from b_non_sy where id_a_non_sy = a_non_sy.id_a_non_sy) as jml');
		$this->db->from('a_non_sy');
		$this->db->where('id_m_j_pendidikan', $id_m_j_pendidikan);
		$this ->db->order_by('akhir_bayar');

		$query = $this->db->get();		
		return $query->result();
	}

	function tholabah($id_a_non_sy)
	{
		$this->db->select('id_b_non_sy,b_non_sy.id_m_tholabah, nama_lengkap, jk, alamat, kelas');
		$this->db->from('b_non_sy');
		$this->db->join('m_tholabah','m_tholabah.id_m_tholabah = b_non_sy.id_m_tholabah');
		$this->db->join('b_kelas','b_kelas.id_m_tholabah = m_tholabah.id_m_tholabah');
		$this->db->join('a_kelas','a_kelas.id_a_kelas = b_kelas.id_a_kelas');
		$this->db->join('m_kelas','m_kelas.id_m_kelas = a_kelas.id_m_kelas');
		$this->db->where('id_a_non_sy', $id_a_non_sy);
		$this->db->where('a_kelas.id_m_th_ajaran', id_ta_aktif());

		$query = $this->db->get();		
		return $query->result();
	}

	function detail_tagihan($id_a_non_sy)
	{
		$this->db->select('id_a_non_sy,nama_non_sy,besar_bayar,mulai_bayar,akhir_bayar,a_non_sy.id_m_j_pendidikan,j_pendidikan,(select count(id_m_tholabah) from b_non_sy where id_a_non_sy = '.$id_a_non_sy.') as jml');
		$this->db->from('a_non_sy');
		$this->db->join('m_j_pendidikan','m_j_pendidikan.id_m_j_pendidikan = a_non_sy.id_m_j_pendidikan');
		$this->db->where('id_a_non_sy', $id_a_non_sy);

		$query = $this->db->get();		
		return $query->result();
	}

	function list_kelas($id_m_th_ajaran,$id_m_j_pendidikan)
	{
		$this->db->select('a_kelas.id_m_kelas, kelas');
		$this->db->from('a_kelas');
		$this->db->join('m_kelas','m_kelas.id_m_kelas = a_kelas.id_m_kelas');
		$this->db->where('id_m_th_ajaran', $id_m_th_ajaran);
		$this->db->where('id_m_j_pendidikan', $id_m_j_pendidikan);

		$query = $this->db->get();		
		return $query->result();
	}

	function list_tholabah_modal($id_m_th_ajaranSkrg,$id_m_j_pendidikan,$id_m_kelas,$id_a_non_sy)
	{
		$this->db->select('b_kelas.id_m_tholabah, nama_lengkap, alamat, jk');
		$this->db->from('b_kelas');
		$this->db->join('m_tholabah','m_tholabah.id_m_tholabah = b_kelas.id_m_tholabah');
		$this->db->join('a_kelas','a_kelas.id_a_kelas = b_kelas.id_a_kelas');
		$this->db->join('m_kelas','m_kelas.id_m_kelas = a_kelas.id_m_kelas');
		$this->db->where('id_m_th_ajaran', $id_m_th_ajaranSkrg);
		$this->db->where('m_tholabah.id_m_j_pendidikan', $id_m_j_pendidikan);
		$this->db->where('a_kelas.id_m_kelas', $id_m_kelas);
		$this->db->where('b_kelas.id_m_tholabah NOT IN (SELECT id_m_tholabah FROM b_non_sy WHERE id_a_non_sy = '.$id_a_non_sy.')');

		$query = $this->db->get();		
		return $query->result();
	}

	function save($dataInsert)
	{
		$query = $this->db->insert('b_non_sy', $dataInsert);
		return $query;
	}

	function delete($id_b_non_sy)
	{
		$this->db->where('id_b_non_sy', $id_b_non_sy);
		$delete = $this->db->delete('b_non_sy');
		return $delete;
	}
}